package com.example.batchprocessing.test;

import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class JdbcItemWriter implements ItemWriter<DealBean>, InitializingBean{

    private JdbcTemplate jdbcTemplate;

    public JdbcItemWriter(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }


    @Override
    public void write(List<? extends DealBean> dealBeans) {

        //备份clear_atm
        String name = "hwl";

        try {
            for( DealBean dealBean : dealBeans ){
                //删除当前表，然后更新
                jdbcTemplate.update( "UPDATE people\n" +
                        "SET first_name = '"+name+
                        "' WHERE person_id=114; ");
	}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // TODO Auto-generated method stub
        System.out.println("-=-=-=-===-----------------=-==-==-=-==");

    }
}
